package mdns

import (
	"fmt"
	"log"
	"time"
)
import "github.com/hepeichun/mdns"

func Run() {
	log.Println("开始检索mdns")
	entriesCh := make(chan *mdns.ServiceEntry, 8)
	go func() {
		for entry := range entriesCh {
			fmt.Println("发现设备")
			fmt.Printf("	名称: %s \n	地址: %s \n	IPv4: %s \n	IPv6: %s \n	主机: %s \n	端口: %s\n	信息字段: %s\n	信息: %s\n	TTL: %d\n",
				entry.Name, entry.Addr, entry.AddrV4, entry.AddrV6, entry.Host, entry.Port, entry.InfoFields, entry.Info, entry.TTL)
		}
	}()

	for true {
		//log.Println("Start the lookup")
		// Start the lookup
		//err := mdns.Lookup("_nvstream_dbd._tcp.", entriesCh)
		err := mdns.Lookup("_ewelink._tcp", entriesCh)
		if err != nil {
			fmt.Println(err)
		}
		time.Sleep(time.Millisecond * 200)
	}

	close(entriesCh)
	log.Println("结束检索mdns")

}
